#!/bin/sh

# Davide.Gustin by SpheraIT

sysdescr=$1
syslocation=$2
syscontact=$3
sysname=$4
rocommunity=$5
restrictip=$6

# Config Files

snmpdconf="/etc/snmp/snmpd.conf"

# Delete Lines

delsysnamesnmpd=`sed -i -r "/^sysdescr/d" $snmpdconf`
delsyslocationsnmpd=`sed -i -r "/^syslocation/d" $snmpdconf`
delsyscontactsnmpd=`sed -i -r "/^syscontact/d" $snmpdconf`
delsysdescrsnmpd=`sed -i -r "/^sysname/d" $snmpdconf`
delrocommunitysnmpd=`sed -i -r "/^rocommunity/d" $snmpdconf`
deltrapcommunitysnmpd=`sed -i -r "/^trapcommunity/d" $snmpdconf`
delincludealldiskssnmpd=`sed -i -r "/^includeAllDisks/d" $snmpdconf`
delrwcommunitysnmpd=`sed -i -r "/^rwcommunity/d" $snmpdconf`

# Insert Lines

echo "includeAllDisks 10%" >> $snmpdconf

if [ "$rocommunity" != "" ]; then
    echo "rocommunity $rocommunity $restrictip" >> $snmpdconf
    echo "trapcommunity $rocommunity" >> $snmpdconf
fi
if [ "$sysname" != "" ]; then
    echo "sysname $sysname" >> $snmpdconf
fi
if [ "$syscontact" != "" ]; then
    echo "syscontact $syscontact" >> $snmpdconf
fi
if [ "$syslocation" != "" ]; then
    echo "syslocation $syslocation" >> $snmpdconf
fi
if [ "$sysdescr" != "" ]; then
    echo "sysdescr $sysdescr" >> $snmpdconf
fi

# Reload snmp configuration

service snmpd reload

exit 0
